import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeOptions;
import static java.lang.Thread.sleep;
import java.util.List;



public class _26 {

        public static void main(String[] args) throws InterruptedException {
            int iage=0;
            ChromeOptions Options= new ChromeOptions();
            //允许所有请求
            Options.addArguments("--remove-allow-origins=*");
            WebDriver webDriver = new ChromeDriver();
            //打开百度首页
            webDriver.get("https://www.baidu.com");
          WebElement element = webDriver.findElement(By.cssSelector(".s_ipt"));//css定位
            //输入做西红柿鸡蛋
           // WebElement element =webDriver.findElement(By.xpath("//*[@id=\"kw\"]"));//xpath定位
            element.sendKeys("做西红柿鸡蛋");
            //找到百度一下按钮
            //点击
            webDriver.findElement(By.cssSelector("#su")).click();
                sleep(9000);
            //校验
            List<WebElement> elements = webDriver.findElements(By.cssSelector("a em"));
            //找到搜索结果
            for (int i=0;i<elements.size();i++){
                //如果返回值有做西红柿，证明测试通过，否则测试不通过
                if (elements.get(i).getText().equals("做西红柿")){
                    iage=1;
                    System.out.println("测试通过");
                    break;
                    }
                }if(iage==0){
                System.out.println("测试不通过");
            }
            }

        }
